const TokenKey = 'token'
const RefreshTokenKey = 'refreshToken'
const UserIdKey = 'userId'
const UserNameKey = 'userName'

//获取token
export function getToken() {
    return localStorage.getItem(TokenKey) || ''
}

//保存用户ID
export function SetUserId(UserId) {
    localStorage.setItem(UserIdKey, UserId)
}

//保存用户名
export function SetUserName(UserName) {
    localStorage.setItem(UserNameKey, UserName)
}

//获取refreshToken
export function getrefreshToken() {
    return localStorage.getItem(RefreshTokenKey) || ''
}

// 保存token和refreshToken
export function setToken(token, refreshToken) {
    localStorage.setItem(TokenKey, token),
        localStorage.setItem(RefreshTokenKey, refreshToken);
}

// 清除token和refreshToken
export function clearToken() {
    localStorage.removeItem(TokenKey);
    localStorage.removeItem(RefreshTokenKey);
}
//清除UserId
export function clearUserId() {
    localStorage.removeItem(UserIdKey);
}
//清除UserName
export function clearUserName() {
    localStorage.removeItem(UserNameKey);
}

//判断是否登录
export function isLogin() {
    let token = getToken();
    if (token) {
        return true
    } else {
        return false
    }
}